//
//  HomePage.swift
//  Uber
//
//  Created by 朱 桓 on 16/1/19.
//  Copyright © 2016年 zhu.huan. All rights reserved.
//

import UIKit

class HomePage: ZhBasePage,BMKMapViewDelegate, UIGestureRecognizerDelegate {
    var leftView:UIView? // 左边视图
    var backControl:UIControl! // 右边视图控制
    var showingLeft:Bool! // 当前左边区域是否显示
    var userPage:UserCenterPage!
    
    var mapView:BMKMapView?
    var locService:BMKLocationService?
    var userCorrdinate:CLLocationCoordinate2D? // 用户当前位置
    var timer:NSTimer? // 定时器实时刷新
    var point:BMKPointAnnotation? // 标点
    var geoCode:BMKGeoCodeSearch?//反地理编码
    var poiSearch:BMKPoiSearch?// 搜索
    var routeSearch:BMKRouteSearch?//搜服轨迹
    
    @IBOutlet var bottomView:UIView?
    @IBOutlet var firstCar:UIButton?
    @IBOutlet var preLabel:UILabel!
    @IBOutlet var bottomImageView:UIImageView!
    @IBOutlet var FeiYong:UILabel! // 最低费用
    @IBOutlet var endPos:UILabel! // 目的地
    @IBOutlet var tuDingBtn:UIButton?// 图钉按钮
    @IBOutlet var searchAdd:UITextField?
    @IBOutlet var topView:UIView?
    
    var btnHelper:FxButtonHelper?
    let moveOffset:CGFloat = 8.0
    var isMoveup:Bool! // 上下移动状态位

    override func viewDidLoad() {
        super.viewDidLoad()
        
        addBackControl()
        addBadiDuMap()
       
        setNavigationItem("account_icon_up.png", selector: Selector("doShowLeft"), isRight: false)
        
        //设置title
        self.navigationItem.titleView = UIImageView(image: UIImage(named: "logo_uber_grey_zh_CN.png"))
        
        btnHelper = FxButtonHelper()
        // 显示在前面
        self.view.bringSubviewToFront(bottomView!)
        // 默认点击的第一个
        self.doSwapCar(firstCar!)
        
        addTapGuestrue()
        self.view.bringSubviewToFront(topView!)
        self.view.bringSubviewToFront(tuDingBtn!)
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?) {
        super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
        
        showingLeft = false
        isMoveup = false
    }
    
    override func viewWillAppear(animated: Bool) {
        super.viewWillAppear(animated)
        // 此处记得不用的时候需要置nil，否则影响内存的释放
        mapView?.delegate = self
        geoCode?.delegate = self
        poiSearch?.delegate = self
        routeSearch?.delegate = self
    }
    
    override func viewDidDisappear(animated: Bool) {
        super.viewDidDisappear(animated)
        
        mapView?.delegate = nil
        geoCode?.delegate = nil
        poiSearch?.delegate = nil
        routeSearch?.delegate = nil
    }
    
    override func viewWillDisappear(animated: Bool) {
        super.viewWillDisappear(animated)
    }
    
    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        
        self.addLeftView()
        self.addUserCenterView()
        
        self.stopTimer()
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        
    }

}
